Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
Hello. Why "display none" is not applied

I want to hide the block where id ends with _event_2 or _event_1. https://i.stack.imgur.com/8pVff.png I slightly corrected the code.

let tabMyMarketHistory = document.getElementsByClassName("market_tab_well_tabs")[0];
let aDisplayNoneListing = document.createElement('a');
let spanDisplayNoneListing = document.createElement('span');
aDisplayNoneListing.id ="displayNoneListingCanceledCreated";
aDisplayNoneListing.className ="market_tab_well_tab";
spanDisplayNoneListing.className ="market_tab_well_tab_contents";
spanDisplayNoneListing.textContent ="Clear";
aDisplayNoneListing.append(spanDisplayNoneListing);
tabMyMarketHistory.append(aDisplayNoneListing);

let DisplayNoneListing =document.getElementById("displayNoneListingCanceledCreated");
DisplayNoneListing.onclick = function() { 
    DisplayNoneListing.className = "market_tab_well_tab market_tab_well_tab_active";
    let itemDetals =document.querySelectorAll(`div[id^="history_row"]`);
    if (itemDetals.length > 0) {
        for (let i= 0; i < itemDetals.length; i++) {
            if (itemDetals[i].id.includes('event_1') || itemDetals[i].id.includes('event_2')) {
                document.getElementById(itemDetals[i].id.toString()).style.display = 'none';
                console.log(document.getElementById(itemDetals[i].id.toString()));
            }
        }
        
    }
};
        
    }

Thank you very much for your comments.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It works for me, it is hidden, but not without when I delete the 1 from the end of the ID:

let itemDetals = document.querySelectorAll(`div[id^="history_row"]`);
if (itemDetals.length > 0) {
  for (let i = 0; i < itemDetals.length; i++) {
    if (itemDetals[i].id.includes('_event_1') || itemDetals[i].children[6].firstElementChild.id.includes('_event_2')) {
        document.getElementById(itemDetals[i].id.toString()).style.display = 'none';
        console.log(itemDetals[i].id.toString());
    }
  }
}
<div class="market_listing_row market_recent_listing_row" id="history_row_3297188894015887588_event_1">Hi</div>

about 4 years ago · Juan Pablo Isaza Report

0

Not really sure what you're trying to accomplish with the following line. Can you explain it?

itemDetals[i].children[6].firstElementChild.id.includes('_event_2')

I changed it to look for event_2 just like the first one like I thought and it works fine, even on children of the div (if that is what you were trying to accomplish, that's my guess). You basically target all divs in the DOM whether they are children or not.

PS: Two small nitpicks. You should rename detals to details (misspelling error) and change the includes to only look for event_1 or event_2, since the extra _ is kind of unnecessary.


Here's the code:

<html>
    <body>
        <div class="market_listing_row market_recent_listing_row" id="history_row_3297188894015887588_event_3">
            Event 3 - Parent
            <div class="market_listing_row market_recent_listing_row" id="history_row_329718889ee4015887588_event_2">Event 1 - Child</div>
        </div> 
        <div class="market_listing_row market_recent_listing_row" id="history_row_3297188894015887588_event_1">
            Event 1 - Parent
            <div class="market_listing_row market_recent_listing_row" id="history_row_329714015887588_event_2">Event 2 - Child</div>
        </div> 

        <script>
            let itemDetals = document.querySelectorAll(`div[id^="history_row"]`);
            if (itemDetals.length > 0) {
                for (let i= 0; i < itemDetals.length; i++) {
                    if (itemDetals[i].id.includes('event_1') || itemDetals[i].id.includes('event_2')) {
                        document.getElementById(itemDetals[i].id.toString()).style.display = 'none';
                    }
                }
            }
        </script>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!